// pages/ta/ta.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        avatarUrl: defaultAvatarUrl,
        username: '',
        firstPassword: '',
        secondPassword: '',
        phoneNumber: '',
        state: false,
        phonestate: false,
        imgstate: false,
        userstate: false
    },
    username(e) {
        this.setData({
            username: e.detail.value,
            state: false,
            phonestate: false,
            imgstate: false,
            userstate: false
        })

    },
    imagebut() {
        this.setData({
            imgstate: true,
            state: false,
            phonestate: false,
        })
    },
    firstPassword(e) {
        this.setData({
            firstPassword: e.detail.value, // 更新数据
            state: false,
            phonestate: false,
            imgstate: false,
            userstate: false
        });
    },

    secondPassword(e) {
        this.setData({
            secondPassword: e.detail.value, // 更新数据
            state: false,
            phonestate: false,
            imgstate: false,
            userstate: false
        });
    },
    phoneNumber(e) {
        this.setData({
            phoneNumber: e.detail.value,
            state: false,
            phonestate: false,
            imgstate: false,
            userstate: false
        })
    },

    butAddUser() {
        let phone = this.data.phoneNumber.length;
        if (this.data.username != "") {
            if (phone == 11) {
                if (this.data.firstPassword == this.data.secondPassword) {
                    wx.request({
                        url: 'http://192.168.217.70:8080/index/register?username=' + this.data.username + '&password=' + this.data.firstPassword + '&phone=' + this.data.phoneNumber, //仅为示例，并非真实的接口地址
                        method: "POST",
                        header: {
                            'content-type': 'application/json' // 默认值
                        },
                        success(res) {
                            console.log(res.data)
                        }
                    })
                } else {
                    this.setData({
                        state: true,
                        phonestate: false,
                        imgstate: false,
                        userstate: false
                    })
                }
            } else {
                this.setData({
                    phonestate: true,
                    state: false,
                    imgstate: false,
                    userstate: false
                })
            }
        } else {
            this.setData({
                state: false,
                phonestate: false,
                imgstate: false,
                userstate: true
            })
        }
    }
})